package engine.loaders
{
	public class RxManifest
	{
		private static var s_manifestPath:String;
		private static var s_blobPath:String;
		private static var s_manifest:Array;
		private static var s_callback:Function;
		
		public function RxManifest()
		{
		}
		
		public static function SetPaths(manifestPath:String, blobPath:String) : void
		{
			s_manifestPath = manifestPath;
			s_blobPath = blobPath;
		}
		
		public static function GetBlob(blob:String) : String
		{
			if (s_manifest == null)
			{
				return null;
			}
			
			var index:int = s_manifest.indexOf(blob);
			if (index == -1)
			{
				return null;
			}
			var str:* = s_manifest[(index + 1)];
			return s_blobPath + str;
		}
		
		public static function GetSize(param1:String) : int
		{
			if (s_manifest == null)
			{
				return 0;
			}
			var _loc_2:* = s_manifest.indexOf(param1);
			if (_loc_2 == -1)
			{
				return 0;
			}
			var _loc_3:* = s_manifest[_loc_2 + 2];
			return parseInt(_loc_3);
		}
		
		public static function GetManifestPath() : String
		{
			return s_manifestPath;
		}
		
		public static function GetBlobPath() : String
		{
			return s_blobPath;
		}
		
		public static function Load(callback:Function) : void
		{
			var type:int = 0;
			s_callback = callback;
			if (s_manifestPath == null || s_blobPath == null)
			{
				if (s_callback != null)
				{
					s_callback();
				}
				return;
			}
			if (s_blobPath.lastIndexOf("/") != (s_blobPath.length - 1))
			{
				s_blobPath = s_blobPath + "/";
			}
			if (s_manifestPath.indexOf("http") == 0)
			{
				type = RxLoader.SOURCE_REMOTE;
			}
			else
			{
				type = RxLoader.SOURCE_LOCAL;
			}
			var loader:RxLoader = new RxLoader(s_manifestPath, RxLoader.TYPE_TEXT);
			loader.AddCompletionCallback(new RxLoaderCallback(OnLoadComplete));
			//loader.SetSource(type);
			loader.SetSource(RxLoader.SOURCE_REMOTE);
			loader.SuppressIOError(true);
			loader.Load();
		}
		
		private static function OnLoadComplete(callback:RxLoaderCallback) : void
		{
			var text:String = null;
			if (callback.m_result == true)
			{
				text = callback.m_loader.GetText();
				s_manifest = text.split(/\t|\n""\t|\n/);
			}
			if (s_callback != null)
			{
				s_callback();
			}
		}
	}
}